
$(function () {
    // 获取当前时间
    let currentTime = new Date();
    let currentHour = currentTime.getHours();

    let greeting = $("#greeting");
    console.log(greeting)
    // 根据时间设置问候语
    if (currentHour < 12) {
        greeting.text("早上好")
    } else if (currentHour >= 12 && currentHour < 18) {
        greeting.text("下午好");
    } else if (currentHour >= 18 && currentHour < 20) {
        greeting.text("晚上好");
    } else {
        greeting.text("中午好");
    }


    $(".personal_a_img").on({
        mouseenter: function () {
            $(this).children().attr({"src": "http://localhost:8083/resource_packs/images/right_red.png"})
            $(this).css({"color": "#FF6700"})
        },
        mouseleave: function () {
            $(this).children().attr({"src": "http://localhost:8083/resource_packs/images/right_black.png"})
            $(this).css({"color": "#757575"})
        }
    });

    $(".logout-service").on("click",function (){
        $(".hint-window-logout").css("display","block")
    })
    $(".hint-img").on("click",function (){
        $(".hint-window-logout").css("display","none")
    })
    $(".cancel").on("click",function (){
        $(".hint-window-logout").css("display","none")
    })
    const revise = $(".revise-account");
    let inputUtil = new Input_util();
    //动画
    inputUtil.customizeAfloatAnimation($(".phone-number"), $(".phone-title"), revise[0], 0, -20)
    //动画
    inputUtil.customizeAfloatAnimation($(".password-number"), $(".password-title"), revise[1], 0, -20)
    //动画
    inputUtil.customizeAfloatAnimation($(".input-code"), $(".placeholder-code"), revise[2],0, -20)
    let hintImg = $(".hint-img");
    hintImg.on({
        mouseenter: function () {
            hintImg.attr({"src": "http://localhost:8083/resource_packs/images/pop_ups_closes_red.png"})
        }, mouseleave: function () {
            hintImg.attr({"src": "http://localhost:8083/resource_packs/images/pop_ups_closes.png"})
        }
    });
    let code = null;
    //注销前判断输入的账户是否存在
    $(".obtain").on("click",function (){
        let phone= $(".revise-account .phone-number").val()
        const informationId=$(".operate").attr("informationId");
        let password= $(".revise-account .password-number").val()
        const account = new Account();
        account.accountSelect(phone,password,informationId).then(res => {
            console.log(res)
            if(res>0){
                code = res;
            }
        })
    })
    $(".confirm").on("click",function (){
        const  captcha = $(".choose .input-code").val();
        const informationId=$(".operate").attr("informationId");
        if (captcha!=="" && captcha===code){
            const account = new Account();
            account.orderSelect(informationId).then(res => {
                if(res>0){
                    const r=confirm("你还有"+1+"个订单存在，是否要注销？");
                    if (r==true)
                    {
                        account.deleteSelect(informationId).then(resDelete => {
                            alert(resDelete)
                            if(resDelete){
                                window.location.href="http://localhost:8083/www.xiaomi.com/login";
                            }
                        })
                    }
                    else
                    {
                        window.location.href="http://localhost:8083/www.xiaomi.com/center";
                    }
                }else{
                    account.deleteSelect(informationId).then(resDelete => {
                        alert(resDelete)
                        if(resDelete){
                            window.location.href="http://localhost:8083/www.xiaomi.com/login";
                        }
                    })
                }
            })
        }else {
            alert("验证码格式错误")
        }
    })
})
